package com.xianbeiying.app.ckgl.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xianbeiying.app.ckgl.R;
import com.xianbeiying.app.ckgl.bean.SysConfigBean;

import java.util.List;

/**
 * 系统配置数据适配
 */
public class ItemSystemConfigsAdapter extends BaseAdapter{
    private Context context;
    private List<SysConfigBean.ConfigBean> systemConfigBeanArrayList;
    public ItemSystemConfigsAdapter(Context context, List<SysConfigBean.ConfigBean> systemConfigBeanArrayList) {
        this.context = context;
        this.systemConfigBeanArrayList=systemConfigBeanArrayList;
    }
    @Override
    public int getCount() {
        return systemConfigBeanArrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_system_plantype, parent, false);
            holder = new ViewHolder();
            holder.tv_name=(TextView) convertView.findViewById(R.id.tv_name);
            holder.tv_color=(TextView) convertView.findViewById(R.id.tv_color);
            holder.tv_number=(TextView) convertView.findViewById(R.id.tv_number);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_color.setBackgroundColor(Color.parseColor("#"+systemConfigBeanArrayList.get(position).getStepColor()));
        holder.tv_name.setText(systemConfigBeanArrayList.get(position).getStepName());
        holder.tv_number.setText(systemConfigBeanArrayList.get(position).getStepDuration()+"天");
        return convertView;
    }
    private class ViewHolder{
        TextView tv_name;
        TextView tv_color;
        TextView tv_number;
    }
}
